home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / ispell40.lha / ispell-4.0 / hash.c < prev    next >
C/C++ Source or Header  |  1993-04-15  |  1KB  |  51 lines

  1. /* Copyright (C) 1990, 1993 Free Software Foundation, Inc.
  2.  
  3.    This file is part of GNU ISPELL.
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2, or (at your option)
  8.    any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include <stdio.h>
  20. #include "ispell.h"
  21. #include "hash.h"
  22.  
  23. /*
  24.  * compute a 15 bit hash code
  25.  */
  26. unsigned int
  27. hash (p)
  28.   register char *p;
  29. {
  30.   register int acc = 0;
  31.   register unsigned char b0;
  32.  
  33.   while (1)
  34.     {
  35.       if ((b0 = *p++) == 0)
  36.     break;
  37.       acc <<= 1;
  38.       acc += b0;
  39.       acc += (*p << 8);
  40.       if (acc < 0)
  41.     {
  42.       acc &= (((unsigned) -1) >> 1);
  43.       acc++;
  44.     }
  45.       if (*p++ == 0)
  46.     break;
  47.     }
  48.  
  49.   return (acc & 0x7fff);
  50. }
  51.